﻿console.log('before');

getUser(1,getRepositories);

console.log('after');

function getRepositories(user){
    getRepositories(user.userName,getCommits);
}

function getCommits(repos){
    getCommits(repos,displayCommits);
}

function displayCommits(commits){
    console.log(commits);
}

function getUser(id){
    return new Promise((resolve,reject)=>{
       // kick off some async work
        setTimeout(() =>{
            console.log('reading a user from a db');

            resolve({ id:id,userName:'mosh' });

        },2000);
    });

}

function getRepositories(username,callback){
    setTimeout(() => {
        console.log('Calling Github api...');
       callback(["repo1","repo2","repo3"]);
    },2000);
}